package com.t14;

/**
 * Created by xuyiwei on 2018/8/7.
 */
class Candy{
    static {System.out.println("Loading Candy");}
}
class Gum{
    static {System.out.println("Loading Gum");}
}
class Cookie{
    static {System.out.println("Loading Cookie");}
}
public class SweetShop {
    public static void main(String[] args) {
        System.out.println("iniside main");
        new Candy();
        System.out.println("After creating Candy");
        try{
            //这个方法回去找Gum类，如果Gum类还没有加载就去加载他
            Class.forName("com.t14.Gum");
        }catch (Exception e){
            //这里会打印Could not find Gum 因为这里的Gum没有被加载
            System.out.println("Could not find Gum");
        }
        System.out.println("After Class.for(\"Gum\")");
        new Cookie();
        System.out.println("After creating Cookie");
        /**
         * output
         iniside main
         Loading Candy
         After creating Candy
         Loading Gum
         After Class.for("Gum")
         Loading Cookie
         After creating Cookie
         */
    }
}

